home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: renaming file names from within C!
- Date: 17 Jan 1996 07:51:59 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4dirdf$t5s@umbc9.umbc.edu>
- References: <4dh7sb$6de@hammerhead.dadd.ti.com>
- NNTP-Posting-Host: f-umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Sudheer Vemulapalli <sudheer@dadd.ti.com> wrote:
- |> I have a question. Please let me know how to do the following.
- |>
- |> How can i move/rename a file in the UNIX system from within a C program.
- |>
- |> Suppose i have two strings "a" and "b".
- |>
- |> char *a, *b;
- |>
- |> which contain the two strings. and let's say that a file exists with its
- |> name same as the string in "b". How can i rename it or mv it so that the
- |> file's name becomes same as string in "a".
- |>
- |> Is there a short way of doing it rather than creating another file with new
- |> name and copying the contents of the old file into the new file and then
- |> removing the old file.
-
- This can be done completely n ANSI C using the rename function(). To do what
- you ask, assuming the variables 'a' and 'b' are valid strings, the call:
-
- rename (b, a);
-
- should make the filename corresponding to string 'b' correspond to string 'a'.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-